﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmStructure.h"
#include "ElementId.h"
#include "UniIdentity.h"
#include "IElementBasicInformation.h"

namespace gcmp
{
    // 封装IInstance接口
    class GM_STRUCTURE_EXPORT IGbmpInstance
    {
    public:
        virtual ~IGbmpInstance();

    public:
        virtual ElementId GetElementId() const = 0;
        virtual const UniIdentity& GetCategoryUid() const = 0;

        // 在接口中增加新的方法时，下面的宏中也需相应增加
    };
}

#define DECLARE_GBMP_INSTANCE_METHODS \
    virtual gcmp::ElementId GetElementId() const override; \
    virtual const gcmp::UniIdentity& GetCategoryUid() const override;

#define DEFINE_GBMP_INSTANCE_METHODS(CLASS_NAME) \
    gcmp::ElementId CLASS_NAME::GetElementId() const { return GetOwnerElement()->GetElementId(); } \
    const gcmp::UniIdentity& CLASS_NAME::GetCategoryUid() const { return GetOwnerElement()->GetBasicInformation()->GetCategoryUid(); }

#define DEFINE_GBMP_INSTANCE_BASE_DATA_METHODS(CLASS_NAME, BASE_DATA) \
    gcmp::ElementId CLASS_NAME::GetElementId() const { return Get##BASE_DATA##__()->GetOwnerElement()->GetElementId(); } \
    const gcmp::UniIdentity& CLASS_NAME::GetCategoryUid() const { return Get##BASE_DATA##__()->GetOwnerElement()->GetBasicInformation()->GetCategoryUid(); }
